#include "SceneCameraSubsystem.h"

#include "Output/Console.h"
#include "Misc/Assert.h"
#include "Scene/CameraComponent.h"

void RSceneCameraManager::RegisterComponent(TSharedObjectPtr<RCameraComponent> InComponent)
{
    Cameras.AddUnique(InComponent);

    if(!CurrentComponent)
    {
        CurrentComponent=InComponent;
    }
}

void RSceneCameraManager::UnregisterComponent(TSharedObjectPtr<RCameraComponent> InComponent)
{
    Cameras.Remove(InComponent);

    if(InComponent==CurrentComponent)
    {
        CurrentComponent=nullptr;
        if(!Cameras.Empty())
        {
            CurrentComponent=Cameras[0];
        }
    }
}

void RSceneCameraManager::ChangeTo(TSharedObjectPtr<RCameraComponent> InComponent)
{   
    GASSERTEXP(InComponent);
    GASSERT(InComponent->GetScene()==GetScene() ,U"不在同一场景")
    Cameras.AddUnique(InComponent);
    CurrentComponent=InComponent;

}

SRawCameraParameters RSceneCameraManager::GetSceneCameraParameter()
{
    if(CurrentComponent)
    {
        return CurrentComponent->GetViewportParameter();
    }
    else
    {
        WH::PrintLine(U"场景中没有相机组件，使用默认的相机参数,请添加组件");
        return SRawCameraParameters();
    }

}
